﻿Imports System.Data.OleDb

Public Class editProfile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_SubmitDetails.Click

        If fu_ProfilePicture.HasFile Then
            Dim picLocationOnServer = Request.MapPath("AccountPictures") & "/" & fu_ProfilePicture.FileName
            fu_ProfilePicture.SaveAs(picLocationOnServer)
        End If


        Dim Conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("MotorcyclesConn").ConnectionString)
        Dim Sql As String = "UPDATE UserAccounts SET FirstName=@f1,SecondName=@f2,OwnedBike=@f3,ModificationSpecialty=@f4,ProfilePicture=@f5 WHERE Username=@f6"
        Dim cmd As OleDbCommand = New OleDbCommand(Sql, Conn)

        Conn.Open()

        cmd.CommandType = CommandType.Text

        cmd.Parameters.AddWithValue("@f1", tb_FirstName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_SecondName.Text)
        cmd.Parameters.AddWithValue("@f3", tb_CurrentBike.Text)
        cmd.Parameters.AddWithValue("@f4", tb_Speciality.Text)
        cmd.Parameters.AddWithValue("@f5", "AccountPictures/" & fu_ProfilePicture.FileName)
        cmd.Parameters.AddWithValue("@f6", User.Identity.Name)

        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class